<?php

namespace app\admin\controller;

use app\admin\model\auth\Roles;
use app\admin\model\channel\Channel;
use think\facade\Session;
use think\facade\View;
use think\Request;

class Admin extends Base
{


    public function index()
    {

        return View();
    }



    public function list(Request $request){




        if($request->isGet() && request()->isAjax()) {
            $list =\app\admin\model\admin\Admin::getAdminList();
            return $this->result($list);
        }

        return \view();
    }

    public function addEdit(Request $request){

        error_reporting(0);
        if($request->isPost() && request()->isAjax()) {

            $data=$request->param();
            if(!$request->param('id')){
                $res=\app\admin\model\admin\Admin::register($data);

                return $this->result($res);
            }else{
                $res=\app\admin\model\admin\Admin::modifyInfo($data);

                return $this->result($res);
            }


        }

        $list=Roles::select();

        $info=\app\admin\model\admin\Admin::where('id',input('id'))->find();

        $channel=Channel::select();

        return View('',['info'=>$info,'roles'=>$list,'channel'=>$channel]);
    }

    public function del(Request $request)
    {

        $info=\app\admin\model\admin\Admin::where('id',input('id'))->find();

        if($info['type']==1){
            return $this->error('不能删除超管');
        }

        \app\admin\model\admin\Admin::where('id',input('id'))->delete();

        return $this->success();
    }






}